using System;
using System.Collections.Generic;
using System.Text;

namespace UrbanChallenge.Common.Integration {
	public static class QK21 {
		static readonly double[] xgk = new double[]   /* abscissae of the 21-point kronrod rule */
			{
				0.995657163025808080735527280689003,
				0.973906528517171720077964012084452,
				0.930157491355708226001207180059508,
				0.865063366688984510732096688423493,
				0.780817726586416897063717578345042,
				0.679409568299024406234327365114874,
				0.562757134668604683339000099272694,
				0.433395394129247190799265943165784,
				0.294392862701460198131126603103866,
				0.148874338981631210884826001129720,
				0.000000000000000000000000000000000
			};

		/* xgk[1], xgk[3], ... abscissae of the 20-point gauss rule. 
			 xgk[0], xgk[2], ... abscissae to optimally extend the 20-point gauss rule */

		static readonly double[] wg = new double[]    /* weights of the 10-point gauss rule */
			{
				0.066671344308688137593568809893332,
				0.149451349150580593145776339657697,
				0.219086362515982043995534934228163,
				0.269266719309996355091226921569469,
				0.295524224714752870173892994651338
			};

		static readonly double[] wgk = new double[]  /* weights of the 21-point kronrod rule */
			{
				0.011694638867371874278064396062192,
				0.032558162307964727478818972459390,
				0.054755896574351996031381300244580,
				0.075039674810919952767043140916190,
				0.093125454583697605535065465083366,
				0.109387158802297641899210590325805,
				0.123491976262065851077958109831074,
				0.134709217311473325928054001771707,
				0.142775938577060080797094273138717,
				0.147739104901338491374841515972068,
				0.149445554002916905664936468389821
			};

		public static void QK21Rule(QuadFunction f, double a, double b, out double result, out double abserr, out double resabs, out double resasc) {
			double[] fv1 = new double[11];
			double[] fv2 = new double[11];
			QuadKronrod.IntegrationQK(11, xgk, wg, wgk, fv1, fv2, f, a, b, out result, out abserr, out resabs, out resasc);
		}
	}
}
